
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:jujij_shop/widget/my_image.dart';
import '../../utils/dio_util.dart';

class Recommend extends StatefulWidget {
  Recommend({this.recommendList});
  //推荐商品列表
  final List<dynamic> recommendList;
  @override
  _RecommendState createState() => _RecommendState();
}

class _RecommendState extends State<Recommend> {

  List<dynamic> recommendList;



  @override
  void initState() {
    super.initState();
    setState(() {
      recommendList=widget.recommendList;
    });
  }

  @override
  Widget build(BuildContext context) {
    return SliverGrid(
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 2,
        crossAxisSpacing: 8.0,
        mainAxisSpacing: 8.0,
        childAspectRatio:0.7,
      ),
      delegate: SliverChildBuilderDelegate(
            (BuildContext context, int index) {
          return Container(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  width: 325.w,
                  height: 325.w,
                  child: ClipRRect(
                    borderRadius: BorderRadius.all(Radius.circular(10)),
                    child: MyImage(
                      imgSrc:recommendList[index]['image'],
                    ),
                  ),
                ),
                SizedBox(
                  height: 20.h,
                ),
                Text(
                  recommendList[index]['productName'],
                  style: TextStyle(
                    color: Colors.black,
                    fontSize: 30.sp,
                  ),
                  overflow: TextOverflow.ellipsis,
                  maxLines: 1,
                  textAlign: TextAlign.left,
                ),
                RichText(
                  text: TextSpan(
                    children:[
                      TextSpan(
                        text:"￥",
                        style: TextStyle(color: Colors.red, fontSize: 30.sp),
                      ),
                      TextSpan(
                        text:"${recommendList[index]['price']}",
                        style: TextStyle(color: Colors.red, fontSize: 35.sp),
                      )
                    ]
                  ),
                )
              ],
            ),
          );
        },
        childCount: recommendList.length,
      ),

    );

  }
}
